package top.mccat.raven;

import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import top.mccat.raven.factory.ConfigFactory;
import top.mccat.raven.listener.OnDamageListener;
import top.mccat.raven.menu.InfoMenu;
import top.mccat.raven.utils.handler.CommanderHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: StrengthMX
 * @Description: TODO
 * @Author: Raven
 * @Date: 2021/7/7
 * @Version: 1.0
 */
public class StrengthMX extends JavaPlugin {
    private ConfigFactory configFactory;
    private final String CMD = "smx";
    private CommanderHandler handler;
    private OnDamageListener damageListener;
    @Override
    public void onLoad() {

    }

    @Override
    public void onEnable() {
        InfoMenu.displayAuthorPanel(this);
        initDefaultControl();
    }
    @Override
    public void onDisable() {

    }

    private void initDefaultControl(){
        configFactory = new ConfigFactory(this);
        configFactory.initConfigFileData();
        handler = new CommanderHandler(this);
        damageListener = new OnDamageListener(this);
        Bukkit.getPluginCommand(CMD).setExecutor(handler);
        Bukkit.getPluginCommand(CMD).setTabCompleter(this);
        getServer().getPluginManager().registerEvents(damageListener,StrengthMX.this);
    }

    @Override
    public void reloadConfig() {
        configFactory.reloadFileData();
        handler.reloadConfig(configFactory);
        damageListener.setFactory(configFactory);
    }

    private String[] subCommands = {"normal","luck","safe","success","admin","normalstone","luckstone","safestone","successstone","reload"};
    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
        if (args.length > 1) {
            return new ArrayList<>();
        }
        if (args.length == 0) {
            return Arrays.asList(subCommands);
        }
        return Arrays.stream(subCommands).filter(s -> s.startsWith(args[0])).collect(Collectors.toList());
    }
}
